1 Imports System.Data.SqlClient
2 Public Class frmLogin
3     Dim frm As New frmMain
4
5     Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
6         If Len(Trim(UserID.Text)) =
0 Then
7             MessageBox.Show(
"Please enter user id", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
8             UserID.Focus()
9             Exit Sub
10         End If
11         If Len(Trim(Password.Text)) =
0 Then
12             MessageBox.Show(
"Please enter password", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
13             Password.Focus()
14             Exit Sub
15         End If
16         Try
17             con = New SqlConnection(cs)
18             con.Open()
19             cmd = con.CreateCommand()
20             cmd.CommandText =
"SELECT RTRIM(UserID),RTRIM(Password) FROM Registration where UserID = @d1 and Password=@d2"
21             cmd.Parameters.AddWithValue(
"@d1", UserID.Text)
22             cmd.Parameters.AddWithValue(
"@d2", Encrypt(Password.Text))
23             rdr = cmd.ExecuteReader()
24             If rdr.Read() Then
25                 con = New SqlConnection(cs)
26                 con.Open()
27                 cmd = con.CreateCommand()
28                 cmd.CommandText =
"SELECT usertype FROM Registration where UserID=@d3 and Password=@d4"
29                 cmd.Parameters.AddWithValue(
"@d3", UserID.Text)
30                 cmd.Parameters.AddWithValue(
"@d4", Encrypt(Password.Text))
31                 rdr = cmd.ExecuteReader()
32                 If rdr.Read() Then
33                     UserType.Text = rdr.GetValue(
0).ToString.Trim
34                 End If
35                 If (rdr IsNot Nothing) Then
36                     rdr.Close()
37                 End If
38                 If con.State = ConnectionState.Open Then
39                     con.Close()
40                 End If
41
42                 If UserType.Text =
"Admin" Then
43                     frm.lblUser.Text = UserID.Text
44                     frm.lblUserType.Text = UserType.Text
45                     Dim st As String =
"Successfully logged in"
46                     LogFunc(UserID.Text, st)
47                     Me.Hide()
48                     frm.Show()
49                 End If
50              
51             Else
52                 MsgBox(
"Login is Failed...Try again !", MsgBoxStyle.Critical, "Login Denied")
53                 UserID.Text =
""
54                 Password.Text =
""
55                 UserID.Focus()
56             End If
57             cmd.Dispose()
58             con.Close()
59         Catch ex As Exception
60             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
61         End Try
62     End Sub
63
64     Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
65         End
66     End Sub
67
68     Private Sub LinkLabel2_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
69         Me.Hide()
70         frmChangePassword.Show()
71         frmChangePassword.UserID.Text =
""
72         frmChangePassword.OldPassword.Text =
""
73         frmChangePassword.NewPassword.Text =
""
74         frmChangePassword.ConfirmPassword.Text =
""
75         frmChangePassword.UserID.Focus()
76     End Sub
77
78     Private Sub LoginForm1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
79
80     End Sub
81 End Class


Gõ tìm kiếm nhanh...